/*
 * @lc app=leetcode.cn id=24 lang=javascript
 *
 * [24] 两两交换链表中的节点
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var swapPairs = function (head) {
    let resNodeList = new ListNode(0, head);
    let temp = resNodeList;
    while (temp.next && temp.next.next) {
        const before = temp.next
        const after = temp.next.next

        temp.next = after;
        before.next = after.next;
        after.next = before;
        temp = before
    }
    return resNodeList.next
};
// @lc code=end

